ENTER_RECORD Method
Syntax
Arguments
- var
A dot variable with the field values from the specified table.
Description
Allows for data to be entered when using Xbasic with a Form or Browse. Returns a dot variable that is the validation object.
In this example the .enter_record() method returns a dot variable that contains information about any Field Rule violations that occured.
t = table.open("customer") 'DIM a dot variable with properties that match the fieldnames you want to enter dim r as p r.firstname = "" r.company = "alpha" DIM v as p v = t.enter_record(r) ?v.has_errors = .T. ?v.error.size() = 2 ?v.Format("$(field) = $(error)"+crlf()) = CUSTOMER1->COMPANY = company can't be alpha CUSTOMER1->LASTNAME = Field is required: LASTNAME
In this example a dot variable is created with properties for all of the fields that you want to enter. We enter the 'firstname' and 'company' fields in the customer table. Once the dot variable has been created, the <Tbl>.enter_record() method is called. This method takes as its argument the dot variable with the field values.
This method return a dot variable. The dot variable has an 'has_errors' property which lets you know if the method succeeded or not. If not, then the errors are returned in an array called 'errors' which is a sub-property of the dot variable. The dot variable that is returned by the .enter_record() method is actually an object (the 'validation' object), and it has a .Format() method, which allows you to format the error message into a friendly text or html format ready for display to the user. The format() method can use these placeholders:
- $(field)
Placeholder for the fieldname for which the error occurred
- $(error)
Placeholder for the plain-text error message
- $(errorhtml)
Placeholder for the HTML formatted error message
In the above example, the .Format() method is called with this argument:
"$(field) = $(error)"+crlf()
The crlf() function is necessary because the .Format() method does not put in line breaks between each message. The string "$(field) = $(error)" contains two placeholders which get replaced by each field for which an error occurred and by the corresponding error message.
See Also